(** Types and Syntax Trees used in the APython compiler *)

(** {2 Types} *)

(** The type of all expressions *)
type expr_type =
    Type_arrow of expr_type * expr_type
  | Type_instance of (string * expr_type) list
;;

type type_predicate =
    Pred_Equal of expr_type     (** the type is exactly equal *)
  | Pred_Super of type_predicate (** Its a super-type *)
  | Pred_Sub of type_predicate  (** Or its a subtype *)
;;

(** {2 The AST } *)

(** The tree structure of all expressions *)
type expr =
(** Atoms *)
    Integer of int     (** Integers *)
  | String of string   (** Strings  *)
  | Boolean of bool
  | Tuple of expr list
  | Noneval
(** Terms *)
  | Ident of string
  | Call of expr * expr list
  | Attr_ref of expr * string  
(** Operations *)
  | Binop of string * expr * expr
  | Monop of string * expr
(** Complex constructions *)
  | Dict_display of (expr * expr) list
  | Lambda_expr of string list * expr
  
and stmt = 
    Assign of expr * expr
  | Stmt_list of stmt list
  | Apodef of string * string
  | Funcdef of string * string list * stmt list
  | Classdef of string * expr * stmt list
  | Expr_stmt of expr
  | Return of expr
  | Pass
  | If_stmt of expr * stmt list * stmt list
  | While_stmt of expr * stmt list
  | For_stmt of expr * expr * stmt list
;;

(** {2 Exceptions in the Compiler } *)

(** A Type checking exception *)
exception ApyTypeException of string;;


